import { defineStore } from 'pinia'
import { Exam } from './state'
import goodStorage from 'good-storage'

function hasProps(data: any) {
    if (Array.isArray(data)) {
        return Boolean(data.length)
    } else if (data.constructor === Object) {
        return Boolean(Object.getOwnPropertyNames(data).length)
    }
}

export default defineStore('examStore', {
    state: () => {
        return {
            exam: {} as Exam
        }
    },
    getters: {
        getStoreExam(state) {
            console.log('sdfsadf');
            return hasProps(state.exam) ? state.exam : goodStorage.get('exam')
        }
    },
    actions: {
        storeExam(exam: Exam) {
            this.exam = exam
        }
    }
})